package com.raymond.queue.client.thread;

import com.raymond.queue.client.config.ThreadPoolConfig;
import com.raymond.queue.client.msg.MessageManages;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * 异步回调线程
 *
 * @author :  raymond
 * @version :  V1.0
 * @date :  2021-07-14 11:39
 */
public class AsyncCallBackThread {
    private ThreadPoolExecutor callBackThreadPool;

    public AsyncCallBackThread(ThreadPoolConfig threadPollManager) {
        this.callBackThreadPool = new ThreadPoolExecutor(threadPollManager.getCorePoolSize(), threadPollManager.getMaximumPoolSize(),
                threadPollManager.getKeepAliveTime(), threadPollManager.getUnit(), threadPollManager.getWorkQueue(),
                threadPollManager.getThreadFactory(), threadPollManager.getHandler());
    }

    public void execute(MessageManages messageManages) {
        callBackThreadPool.execute(messageManages::callback);
    }

}
